﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CottagesOfHope.Core.Concrete;
using CottagesOfHope.Core.Models;
using CottagesOfHope.Core.Abstract;

namespace CottagesOfHope.Core.Repositories
{
    public class CottagesOfHopeRepository : ICottagesOfHopeRepository
    {
        private readonly CottagesOfHopeDb _db;

        public CottagesOfHopeRepository(CottagesOfHopeDb db)
        {
            _db = db;
        }

        public IQueryable<UserProfile> Users
        {
            get { return _db.UserProfiles; }
        }

        public IQueryable<Tasks> Tasks
        {
            get { return _db.Tasks; }
        }

        public IQueryable<Profile> Profiles
        {
            get { return _db.Profiles; }
        }

        public IQueryable<UserProfile> UserProfile
        {
            get { return _db.UserProfiles; }
        }
       /* #region Customers
        public IQueryable<Customer> Customers
        {
            get { return _db.Customers; }
        }

        public void SaveCustomer(Customer customer)
        {
            if (customer.CustomerId == 0)
            {
                _db.Customers.Add(customer);
                _db.Entry(customer).State = EntityState.Added;
            }
            else
            {
                _db.Entry(customer).State = EntityState.Modified;
            }

            _db.SaveChanges();
        }

        public void DeleteCustomer(Customer customer)
        {
            _db.Customers.Remove(customer);
            _db.SaveChanges();
        }
        #endregion*/

        public void DeleteTask(Tasks task)
        {
            _db.Tasks.Remove(task);
            _db.SaveChanges();
        }

        #region User
        public void SaveUser(UserProfile user)
        {
            if (user.UserId == 0)
            {
                _db.UserProfiles.Add(user);
                _db.Entry(user).State = EntityState.Added;
            }
            else
            {
                _db.Entry(user).State = EntityState.Modified;
            }

            _db.SaveChanges();
        }
        #endregion

        #region Profile
        public void SaveProfile(Profile profile)
        {
            if (profile.UserId == 0)
            {
                _db.Profiles.Add(profile);
                _db.Entry(profile).State = EntityState.Added;
            }
            else
            {
                _db.Entry(profile).State = EntityState.Modified;
            }

            _db.SaveChanges();
        }
        #endregion

        #region Task
        public void SaveTask(Tasks task)
        {
            if (task.TaskId == 0)
            {
                _db.Tasks.Add(task);
                _db.Entry(task).State = EntityState.Added;
            }
            else
            {
                _db.Entry(task).State = EntityState.Modified;
            }

            _db.SaveChanges();
        }



        #endregion

        public void Dispose()
        {
            _db.Dispose();
        }
    }
}
